package com.rotsel.mh3udb.app.lists;

import com.rotsel.mh3udb.app.ListModels.WeaponUpgradeModel;
import com.rotsel.mh3udb.app.models.WeaponModel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by rots on 20.02.14.
 */
public class WeaponUpgradeList {
    private static Map<Integer, WeaponUpgradeModel> weaponUpgradeFromMap;//weaponId, what is needed for upgrade
    private static Map<Integer, ArrayList<Integer>> weaponUpgradeToMap;//weaponId, what weapons can you get from this weaponId

    private static Map<Integer, WeaponUpgradeModel> getWeaponUpgradeFromMap(){
        if (weaponUpgradeFromMap == null){
            weaponUpgradeFromMap = new HashMap<Integer, WeaponUpgradeModel>(50);
            //TODO: fill weapon upgrade map
        }
        return weaponUpgradeFromMap;
    }

    private static Map<Integer, ArrayList<Integer>> getWeaponUpgradeToMap(){
        if(weaponUpgradeToMap == null){
            weaponUpgradeToMap = new HashMap<Integer, ArrayList<Integer>>(50);
            for(WeaponModel item : WeaponList.getAllWeapons()){
                if(!weaponUpgradeToMap.containsKey(item.getWeaponUpgradeId())){
                    weaponUpgradeToMap.put(item.getWeaponUpgradeId(), new ArrayList<Integer>());
                }
                ArrayList<Integer> list = weaponUpgradeToMap.get(item.getWeaponUpgradeId());
                list.add(item.getId());
            }
        }
        return weaponUpgradeToMap;
    }

    public static ArrayList<WeaponUpgradeModel> getWeaponUpgradeToById(int id){
        ArrayList<Integer> weaponUpgradeIds = getWeaponUpgradeToMap().get(id);
        if(weaponUpgradeIds == null || weaponUpgradeIds.size() == 0){
            return new ArrayList<WeaponUpgradeModel>();
        }

        ArrayList<WeaponUpgradeModel> result = new ArrayList<WeaponUpgradeModel>(weaponUpgradeIds.size());
        for(Integer item : weaponUpgradeIds){
            result.add(getWeaponUpgradeFromById(item));
        }
        return result;
    }

    public static WeaponUpgradeModel getWeaponUpgradeFromById(int id){
        return getWeaponUpgradeFromMap().get(id);
    }

    public static int size(){
        return getWeaponUpgradeFromMap().size();
    }


}
